/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including but not limited to the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to provide persons with access to the Software
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGE OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

export type InteractionEventType =
  | 'click'
  | 'doubleClick'
  | 'longPressStart'
  | 'longPressEnd'
  | 'dragStart'
  | 'dragEnter'
  | 'dragMove'
  | 'dragLeave'
  | 'dragOver'
  | 'drop'
  | 'swipe'
  | 'scroll'
  | 'pinchStart'
  | 'pinchMove'
  | 'pinchEnd'
  | 'contextMenu'
  | 'hover'
  | 'hoverMove';

export interface FingerInfo {
  id: number;
  globalX?: number;
  globalY?: number;
  localX?: number;
  localY?: number;
  displayX?: number;
  displayY?: number;
  hand?: 'LEFT' | 'RIGHT' | 'NONE' | string;
}
export interface PointerState {
  target: HTMLElement;
  x?: number;
  y?: number;
  deltaX?: number;
  deltaY?: number;
  velocityX?: number;
  velocityY?: number;
  hand?: 'LEFT' | 'RIGHT' | 'NONE' | string,
  source?: 'mouse' | 'touchScreen' | 'unknown' | string;
  sourceTool?: 'mouse' | 'finger' | 'unknown' | string;
  axisHorizontal?: number;
  axisVertical?: number;
  fingerList?: FingerInfo[];
  windowX: number;
  windowY: number;
  displayX?: number;
  displayY?: number;
  repeat?: boolean;
  offsetX?: number;
  offsetY?: number;
  scale?: number;
  pinchCenterX?: number;
  pinchCenterY?: number;
  speed?: number;
  velocity?: number;
  pressure?: number;
  angle?: number;
  stopPropagation?: Function;
}

export interface PointerOptions {
  distanceThreshold?: number;     // 单机事件移动阈值
  clickTimeout?: number;          // 单击识别超时 (默认250ms)
  doubleTapThreshold?: number;    // 双击最大间隔 (默认300ms)
  longPressThreshold?: number;    // 长按最短时间 (默认500ms)
  direction?: string;             // 轻扫方向
  speed?: number;                 // 轻扫最小速度 (默认0.1px/ms)
  scrollDirection?: string;       // 滚动方向
  scrollDistance?: number;        // 滚动的最短距离(默认5px)
  scaleDistance?: number;         // 缩放的最短距离
  angle?: number;                 // 旋转角度
  enableHover?: boolean;          // 是否开启悬浮（默认false）
  enableContextMenu?: boolean;    // 是否开启上下文菜单（默认false）
  enableClick?: boolean;          // 是否启用单击 (默认false)
  enableDoubleClick?: boolean;    // 是否启用双击 (默认false)
  enableLongPress?: boolean;      // 是否启用长按 (默认false)
  enableDrag?: boolean;           // 是否启用拖拽 (默认false)
  enableSwipe?: boolean;          // 是否启滑动 (默认false)
  enableScroll?: boolean;         // 是否启用滚动 (默认false)
  enableScale?: boolean;          // 是否启用缩放 (默认false)
  enableRotate?: boolean;         // 是否启用旋转 (默认false)
}

export interface GestureHandlers {
  onClick?: (e: PointerState) => void;
  onDoubleClick?: (e: PointerState) => void;
  onLongPressStart?: (e: PointerState) => void;
  onLongPressEnd?: (e: PointerState) => void;
  onLongPressCancel?: (e: PointerEvent) => void;
  onDragStart?: (e: DragEvent) => void;
  onDragMove?: (e: DragEvent) => void;
  onDragEnter?: (e: DragEvent) => void;
  onDragLeave?: (e: DragEvent) => void;
  onDrop?: (e: DragEvent) => void;
  onSwipe?: (e: PointerState) => void;
  onScroll?: (e: PointerState) => void;
  onPinchStart?: (e: PointerState) => void;
  onPinchMove?: (e: PointerState) => void;
  onPinchEnd?: (e: PointerState) => void;
  onContextMenu?: (e: MouseEvent | TouchEvent) => void;
  onHover?: (e: PointerState) => void;
  onHoverMove?: (e: PointerState) => void;
  onRotateStart?: (e: PointerState) => void;
  onRotateMove?: (e: PointerState) => void;
  onRotateEnd?: (e: PointerState) => void;
}

type Direction = 'All' | 'Horizontal' | 'Vertical' | 'Left' | 'Right' | 'Up' | 'Down' | 'None';
// @ts-ignore
export type DirectionParam = Direction | `${Direction}&${DirectionParam}` | `${Direction}|${DirectionParam}`;